package source.home;




import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class register extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
    }
    public void home_click(View button)
    {
    
    	String server = "http://smsever4guni.appspot.com/";
    	///////////code : take data from text views///////
    	EditText username = (EditText) findViewById(R.id.username);
    	EditText password = (EditText) findViewById(R.id.password);
    	EditText email = (EditText) findViewById(R.id.email);
    	
 
    	//////////code : http client code///////

    	InputStream is = null;
    	String result="";
    	String url = server+"smseverguniappengine?username="+username.getText()+"&password="+password.getText()+"&email="+email.getText();
    	try
		{
        HttpClient httpclient = new DefaultHttpClient();
      
        HttpGet HttpGet = new HttpGet(url);
        
        HttpResponse response = httpclient.execute(HttpGet);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        
////////////////Shared Preference memory is created///////////
       	createshp("username",username.getText().toString());
    	System.out.println("sh kosam"+username.getText());
    	
            System.out.println(username.getText());
            System.out.println(password.getText());
            System.out.println(email.getText());
            Intent intent = new Intent();
        	intent.setClass(this,home.class);
        	startActivity(intent);
        
        
		}
		
    	catch(Exception e)
    	{
        Log.e("log_tag", "Error in http connection "+e.toString());
        username.setText("Error");
    	password.setText("Error");
    	email.setText("Error");
       	}
    	
    	/////////////code : Home Page/////////
    	
    	///////////sample code json object/////////////////////
    
    }
    public void createshp(String key,String value)
    {
    	SharedPreferences sharedPreferences = getSharedPreferences(key,MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.commit();
    }   
    
}